import { uploadImg } from '../api/common';
import { mapActions, mapState } from 'vuex';

export default {
  data() {
    return {
      hash: '',
    };
  },
  created() {
  },
  computed: {
    ...mapState(['bucket_domain_token'])
  },
  methods: {
  	...mapActions(['getUrlAndTokenOfImageUpload']),
    async onUploadImageMixins(file) {
      await this.getUrlAndTokenOfImageUpload();
      const formData = new FormData()
      formData.append('file', file)
      formData.append('token', this.bucket_domain_token)
      const { status, data } = await uploadImg (formData)
      if (status !== 200) return
      this.hash = data.hash
    },
  },
};
